package com.tubang.logistics.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tubang.logistics.entity.InvoiceEntity;
import com.tubang.logistics.mapper.InvoiceMapper;
import com.tubang.logistics.service.IInvoiceService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tubang.logistics.util.DateUtils;
import com.tubang.logistics.vo.InvoiceListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 发票表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2017-12-18
 */
@Service
public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, InvoiceEntity> implements IInvoiceService {

	@Autowired
	private InvoiceMapper invoiceMapper;

	@Override
	public Map<String, Object> listInvoice(String userId, boolean carrier, Integer status, String content, Integer page, Integer rows) {
		Map<String, Object> result = new HashMap<>();

		PageHelper.startPage(page, rows);
		List<InvoiceListVO> invoiceListVOS = invoiceMapper.listInvoice(userId, carrier, status, content);
		Page pageBean = (Page) invoiceListVOS;

		invoiceListVOS.forEach(invoiceListVO -> {
			invoiceListVO.setCreateTimeName(DateUtils.getyyyyMMddHHmmss(invoiceListVO.getCreateTime()));
		});

		result.put("result", invoiceListVOS);
		result.put("total", pageBean.getTotal());
		return result;
	}
}
